home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4993 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.8 KB  |  61 lines

  1. Path: news1.sunbelt.net!dial-3
  2. From: dking@SunBelt.Net
  3. Newsgroups: comp.lang.c
  4. Subject: Reading directory into array of some kind.
  5. Date: 10 Feb 1996 19:35:55 GMT
  6. Organization: SunBelt.Net INTERNET Access
  7. Message-ID: <4fis2r$tc7@news1.sunbelt.net>
  8. NNTP-Posting-Host: dial-3.r1.gaagst.sunbelt.net
  9. X-Newsreader: News Xpress Version 1.0 Beta #4
  10.  
  11. The following bit of code uses the findfirst/findnext to read all the 
  12. filesname out of the current directory. I had HOPED to be able to put the file 
  13. names into some sort of array but couldn't find a way to make it work. 
  14.  
  15. I have spent the last several days just trying to get an array of file names 
  16. without success.. (I didn't save the code of the unsuccessful attempts) I 
  17. tried moving the ffblk.name into another structure but it wouldn't work. You 
  18. can't use arrays as lvalues and assign them the name, pointer arrays only 
  19. pointed to the last filename read in...
  20.  
  21. several assumptions:
  22.  
  23. A). Yes, I'm new at this.. 
  24.  
  25. B). No the online Borland help files were NOT helpfull... (Turbo C++ for 
  26. Windows ver 3.1)
  27.  
  28. C). The Tutorials I have were also not helpfull.. they usually had the data 
  29. pre-defined or typed in, so examples for pulling a string from a structure to 
  30. an array or another structure were not given..
  31.  
  32. D). None of my other documentation would seem to have any answers.. at least 
  33. none that make sense or explain fully what needed to be done.
  34.  
  35. Any help on this would be greatly appreciated. 
  36.  
  37. Thanks,
  38.  
  39.                     Daryl 
  40.  
  41.  
  42. #include <stdio.h>
  43. #include <dos.h>
  44. int main()
  45. {
  46.   
  47.   struct find_t ffblk;
  48.   int done;
  49.  
  50.   printf("Directory listing \n");
  51.  
  52.   done = _dos_findfirst("*.*",255,&ffblk); //reads all files from directory
  53.   while (!done) 
  54.       {
  55.     printf("  %s\n", ffblk.name);      //print file names
  56.     done = _dos_findnext(&ffblk);
  57.     }
  58.  
  59.  return 0;
  60. }
  61.